package com.zr.controller.client

import com.alibaba.fastjson.JSON
import com.zr.service.client.ClientServer
import com.zr.service.client.impl.ClientServerImpl
import com.zr.service.sys.AuthServer
import com.zr.service.sys.RoleServer
import com.zr.util.RedisUtils
import com.zr.util.Result
import com.zr.vo.lease.Customer
import com.zr.vo.sys.User
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.util.*
import java.util.concurrent.TimeUnit

@RestController
@RequestMapping("/client")
class CustomerController {
    @Autowired
    val clientServer: ClientServerImpl?=null

    @Autowired
    private val redisUtils: RedisUtils?=null

    @RequestMapping("/LoginCustomer")
    fun LoginCustomer(@RequestBody customer: Customer):String{
        val loginCustomer=clientServer?.LoginCustomer(customer)
        println(loginCustomer)
        if(loginCustomer!=null){
            //为当前用户随机生成一个token
            val token= UUID.randomUUID().toString()
            //将token存入redis缓存中
            val retult=redisUtils?.set(token,loginCustomer,15L, TimeUnit.MINUTES)
            //登录成功时直接返回Token
            return JSON.toJSONString(Result(true,token,loginCustomer))
        }
        return JSON.toJSONString(Result(false,"登录失败！",null))
    }
}